<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>自动签离服务</title>
    <!-- css代码 start -->
    <link href="../../../css/mui.min.css" rel="stylesheet"/>
    <link href="../../../css/global.css" rel="stylesheet"/>
    <link href="../../../css/style.css" rel="stylesheet"/>
    <link href="../../../css/task.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../../../css/mui.picker.css">
    <link rel="stylesheet" href="../../../css/mui.poppicker.css">
    <link rel="stylesheet" href="../../../css/task.css">
    <style type="text/css">
        #div {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 65%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover .mui-popover-arrow:after {
            width: 0px;
        }

        #div1 {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 70%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover1 .mui-popover-arrow:after {
            width: 0px;
        }

        #div6 {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 65%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover6 .mui-popover-arrow:after {
            width: 0px;
        }

        .details_con {
            background: #fff;
        }

        .item_box .item .text {
            margin: 5px auto;
        }

        .item_box .item .text span.cen {
            margin-left: 0;
        }

        .item_box .item .text span {
            width: auto;
        }

        .d_int_tp {
            border: 0 !important;
            margin-top: 6px !important;
        }

        .details_con .btm .selectBtn {
            line-height: 28px;
            color: #ffffff;
            background: #ea1e1a;
        }

        .mui-btn-block {
            border: 0;
            font-size: 16px;
            color: #a9a9a9;
        }

        .select-tzstate {
            width: 100%;
            border: 0;
            color: #a9a9a9;
            font-size: 16px;
            text-align: left;
            padding: 15px;
        }

        .mui-bar-nav {
            box-shadow: 0 1px 6px #ea1e1a;
        }

        .selectDate {
            background: url(../../../images/icon_32.png) no-repeat right center !important;
            background-size: 14px 13px !important;
            color: #8E8E93 !important;
        }

        .lpl {
            width: 90px !important;
        }

        .popover .my-content-cell {
            padding: 0;
            margin: 0 10px;
        }

        .popover .arrow-right-position {
            right: -5px;
        }

        input.d_ipt {
            width: 60%;
            background: #fff;
        }
    </style>
    <!-- css代码 end -->
</head>

<body>

<div id="div"></div>
<div id="popover" class="mui-popover shadow popover">
    <p class="title">请确定服务是否全部完成</p>
    <div class="btn_box">

        <span class="fl" id="noTrue">未完成</span>
        <span class="fr red" id="btnYes">已完成</span>
    </div>
</div>

<!-- <div id="div1"></div>
<div id="popover1" class="mui-popover shadow popover" style="height: 320px;">
    <div class="details_con">

        <div class="clum" style="height: auto;">
            <div class="name" ><em class="t_red">*</em>预计上门时间</div>
            <div class="txt" style="height: auto;overflow: auto;width: 100%;">
            <button id='estimatedVisitingTime' class="selectDate mui-btn mui-btn-block mui-btn-select" type='button' mulitline="true" style="margin-bottom: 0;height: auto;text-align: right;">请选择时间</button>
            </div>
        </div>

        <div class="clum">
            <span class="name"><em class="t_red">*</em>预计工时</span>
            <input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')"/>
        </div>
        <div class="clum">
        <span class="name"><em class="t_red">*</em>预计离开时间</span>
        <input id="estimatedDepartureTime" type="text" class="d_ipt" placeholder="自动计算" disabled="disabled"/>
    </div>
    </div>
    <div class="btn_box">
        <span class="fl red" id="saveDoor">确定</span>
        <span class="fr" id="closeDoor">取消</span>
    </div>
</div> -->

<div id="div1"></div>
<div id="popover1" class="mui-popover shadow popover">
    <div class="details_con">
        <div class="my-content-cell">
            <div class="inline-block" id="pjcgqd">
                <em>查看计划安排</em>
                <span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
            </div>
        </div>
        <div class="clum" style="margin: 0 10px;">
            <span class="name">预计上门时间<em class="t_red">*</em></span>
            <button id='estimatedVisitingTime' type="button" class="selectDate">请选择时间</button>
        </div>
        <div class="clum" style="margin: 0 10px;">
            <span class="name">预计工时<em class="t_red">*</em></span>
            <input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')"/>
        </div>
        <div class="clum" style="margin: 0 10px;">
            <span class="name">预计离开时间<em class="t_red">*</em></span>
            <input id="estimatedDepartureTime" type="text" class="d_ipt" placeholder="自动计算" disabled="disabled"/>
        </div>
    </div>

    <div class="btn_box">

        <span class="fl" id="closeDoor" onclick="closeDoor()">取消</span>
        <span class="fr red" id="saveDoor">确定</span>
    </div>
</div>

<div id="div6"></div>
<div id="popover6" class="mui-popover shadow popover">
    <p class="title" id="title">与您之前的工作计划时间冲突，是否确定？</p>
    <div class="btn_box">

        <span class="fl" onclick="closepop6()">取消</span>
        <span class="fr red" id="quedingupdate6">确定</span>
    </div>
</div>

<!-- html代码 start -->
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">自动签离服务</h1>
</header>
<div class="mui-content">

    <div class="details_con select_con" id="search">
        <div class="clum">
            <input type="text" class="d_int_tp" id="customerName" placeholder="输入客户名称"/>
        </div>
        <div class="clum">
            <!-- <input type="text" class="d_int_tp" id="serviceType" placeholder="输入服务类型" /> -->
            <span class="txt" style="width: 100%;">
						<input type="hidden" id="serviceTypeValue"/>
						<button id='serviceType' class="mui-btn mui-btn-block mui-btn-select select-tzstate"
                                type='button'>请选择服务子类型</button>
					</span>
        </div>
        <div class="clum">
            <input type="text" class="d_int_tp" id="instrumentSerialNumber" placeholder="输入仪器序列号"/>
        </div>
        <div class="btm autoHeight">
            <p class="selectBtn" id="searchBtn" onclick="initData()">查 询</p>
        </div>
    </div>

    <div class="details_con" style="margin: 30px 0 0 0;">
        <div class="item_box" id="itemBox">
        </div>
    </div>
    <div style="height: 50px;"></div>
</div>
<!-- html代码 end -->

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../js/mui.min.js"></script>
<script src="../../../js/utils/h.js"></script>
<script src="../../../js/constant.js"></script>
<script src="../../../js/common.js"></script>
<script src="../../../js/utils/base64.js"></script>
<script src="../../../js/utils/md5.js"></script>
<script src="../../../js/utils/sortMap.js"></script>
<script src="../../../js/utils/http.js"></script>
<script src="../../../js/app.js"></script>
<!-- 基础js end -->
<script src="../../../js/sqliteTools.js"></script>
<script src="../../../js/mui.picker.js"></script>
<script src="../../../js/mui.poppicker.js"></script>
<script src="../../../js/utils/rolldate.min.js"></script>
<script type="text/javascript" charset="utf-8">
    var planId
    var serviceNoticeId
    var serviceNo
	var customerName
    var estimatedVisitingTime
    var estimatedWorkingHours
    var estimatedDepartureTime
    var wcState
    var autoOutLogFlag = false

    function closepop6() {
        mui("#popover6").popover('hide', document.getElementById("div6"));
         autoOutLogFlag = false
    }

    (function ($, doc) {
        $.init();

        new Rolldate({
            el: '#estimatedVisitingTime',
            format: 'YYYY-MM-DD hh:mm',
            beginYear: 2015,
            endYear: 2050,
            trigger: 'click',
            lang: {
                title: '请选择预计上门时间',
            },
            confirm: function (date) {
                jisuan(date)
            }
        })

        $.plusReady(function () {
            var self = plus.webview.currentWebview();

            // 初始化数据
            initData();

            // 确定完成全部服务  签离操作
            h("#btnYes").tap(function () {
                wcState = "yiwancheng"
                findLog()
            });

            // 取消操作 未完成
            h("#noTrue").tap(function () {
                mui("#popover").popover('hide', document.getElementById("div"));
                wcState = "weiwancheng"
                findLog()
            });

            // 查看计划安排
            h("#pjcgqd").tap(function () {
                app.jumpTo("/view/service/taskDetails/task_details.html", "view/service/taskDetails/task_details.html",
                    {
                        serviceNoticeId: serviceNoticeId,
                        serviceNo: serviceNo,
                        enginnerId: app.getUser().enginnerId
                    }
                );
            });

            h("#saveDoor").tap(function () {
                app.showWaiting('正在提交...')

                // 调用计算方法
                jisuan('1');
                estimatedVisitingTime = h("#estimatedVisitingTime").html();
                if (estimatedVisitingTime == null || estimatedVisitingTime == "" || estimatedVisitingTime == "请选择时间") {
                    app.closeWaiting()
                    app.toast("请选择预计上门时间");
                    return
                }
                estimatedWorkingHours = h("#estimatedWorkingHours").val();
                if (estimatedWorkingHours == null || estimatedWorkingHours == "") {
                    app.closeWaiting()
                    app.toast("请输入预计工时");
                    return
                }
                estimatedDepartureTime = h("#estimatedDepartureTime").val();

                var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
                var newDate = new Date().getTime();
                if (evt <= newDate) {
                    app.closeWaiting()
                    app.toast("预计上门时间不可以小于当前时间");
                    return
                }

                ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsList", {
                    "enginnerId": app.getUser().enginnerId,
                    "estimatedVisitingTime": estimatedVisitingTime,
                    "estimatedDepartureTime": estimatedDepartureTime,
                    "planId": planId
                }, function (data) {
                    //console.log(JSON.stringify(data))
                    if (data.code == 200) {
                        saveIn()
                    } else {
                        app.closeWaiting()
                        mui("#popover6").popover('toggle', document.getElementById("div6"));
                    }
                }, function (errorMsg) {
                    app.closeWaiting()
                    app.toast(errorMsg)
                    console.log(JSON.stringify(errorMsg))
                });


            });

            h("#quedingupdate6").tap(function () {
                app.showWaiting('正在提交...')
				mui("#popover6").popover('hide', document.getElementById("div6"));
                saveIn()
            })

            // 取消方法 关闭弹窗
            h("#closeDoor").tap(function () {
                mui("#popover").popover('hide', document.getElementById("div"));
                mui("#popover1").popover('hide', document.getElementById("div1"));
                autoOutLogFlag = false
            })

            // 服务子类型下拉
            h('#serviceType').tap(function () {
                var userPicker = new $.PopPicker();
                ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
                    tableName: 'snsubtype',
                    engineerId: app.getUser().enginnerId
                }, function (data) {
                    console.log(JSON.stringify(data))
                    if (!data) {
                        app.toast("无下拉内容")
                        return
                    }
                    // 数组指定位置插入数据
                    data.splice(0, 0, {"text": "请选择服务子类型", "value": ""});
                    userPicker.setData(data);
                    userPicker.show(function (items) {
                        h('#serviceType').html(items[0].text)
                        h('#serviceTypeValue').val(items[0].value)
                        userPicker.dispose()
                    });
                });
            });
			
			h('.mui-action-back').tap(function () {
				var noticeMenu=plus.webview.getWebviewById('view/service/notice/noticeMenu.html');
				if(noticeMenu){
					noticeMenu.evalJS('getNoticeCount()')
				}
			});
        });
    }(mui, document));


    function chuli(pId, custName) {
        planId = pId;
		customerName = custName;
        serviceNoticeId = document.getElementById(planId).getAttribute('serviceNoticeId');
        serviceNo = document.getElementById(planId).getAttribute('serviceNo');
        // console.log("planId==:"+planId+"	serviceNoticeId==:"+serviceNoticeId+"	serviceNo==:"+serviceNo)
		// 查询是否有已提交并且服务状态为已完成的服务报告
		ajaxGet(BASE_URL + "cc/report/info/checkReportResult", {
			"serviceNo": serviceNo
		}, function(data) {
			app.closeWaiting()
			if (data.code === 200) {
				if (data.data && data.data.length > 0) {
					wcState = "yiwancheng"
					findLog()
				} else {
					mui("#popover").popover('toggle', document.getElementById("div"));
				}
			} else {
				app.toast(data.msg)
			}
		}, function(errorMsg) {
			app.closeWaiting()
			app.toast(errorMsg)
		});
    }

    function saveIn() {
        ajaxGet(BASE_URL + "cc/PlanDetails/fseSignOffAutoAgain", {
            "serviceNoticeId": serviceNoticeId,
            "serviceNo": serviceNo,
            "enginnerId": app.getUser().enginnerId,
            "planId": planId,
            "estimatedVisitingTime": estimatedVisitingTime,
            "estimatedWorkingHours": estimatedWorkingHours,
            "estimatedDepartureTime": estimatedDepartureTime
        }, function (data) {
            app.closeWaiting()
            if (data.code == 200) {               
                mui("#popover").popover('hide', document.getElementById("div"));
                mui("#popover1").popover('hide', document.getElementById("div1"));
				
				if(data.data && data.data.length > 0){
					// 判断是否存在离线数据，
					var enginnerId = app.getUser().enginnerId;
					var fseName = app.getUser().name;
					var sqliteTool = new sqliteTools(); 
					sqliteTool.openDatabase();
					for (var i = 0; i < data.data.length; i++) {
						var resData = data.data[i];		
						sqliteTool.selectServiceByNoticeId(enginnerId, resData.serviceNoticeId, resData, function(flag, offlineData, callBackData) {
							if(flag){
								if (offlineData && offlineData.length > 0) {
									if(callBackData.state == "4"){
										sqliteTool.deleteServiceData(offlineData[0].planId, function(flag) {
											console.log("删除本地数据"+flag)
										})
									} else {
										sqliteTool.insertServiceSignOffAginData(offlineData[0].id, callBackData.planId, function(flag) {
											console.log("更新计划数据"+flag)
										})
									}
								} else {
									sqliteTool.insertServiceBaseData(callBackData.serviceNo, callBackData.serviceNoticeId, callBackData.planId, customerName, callBackData.instrumentId, callBackData.instSn, callBackData.acceptTime, enginnerId, fseName, callBackData.serviceType, callBackData.subServiceType, function (flag) {
										console.log("插入计划数据"+flag)
									})
								}
							}
						});
					}
					setTimeout(function() {
						sqliteTool.closeDB();
					}, 200);
				}
				app.toast('操作成功')
                // var assignList = plus.webview.getWebviewById('view/service/notice/autoCheckedOutList.html');
                // assignList.evalJS('initData()')

                // 20200525 修复文档（客户提出20200524测试反馈）93：自动签离的服务页面跳转见“参考-页面跳转6.1”，填写工作日志之后应有相应的页面跳转5.1.2/5.1.3，而不是直接跳转到待接受列表。
                /* var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
                if(indexFSE){
                    indexFSE.evalJS('getList("1")')
                }
                var self = plus.webview.currentWebview();
                var checkedOutList = plus.webview.getWebviewById('view/service/notice/checkedOutList.html');
                if(checkedOutList){
                    checkedOutList.evalJS('getList()')
                    mui.back()
                }else{
                    var checkedOutList1 = plus.webview.create('/view/service/notice/checkedOutList.html','view/service/notice/checkedOutList.html')
                    checkedOutList1.show()
                    self.close();
                } */
				initData()
                if (autoOutLogFlag) {
                    // quanbuwanchengOnlysave();
                    app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html",
                        {
                            serviceNoticeId: serviceNoticeId,
                            serviceNo: serviceNo,
                            planId: planId,
                            checkOutList: true,
                        });
                    autoOutLogFlag = false
                    return
                }
                // 5.1.3已填写工作日志，服务通知状态为：已签离 （页面含添加报告、签离按钮）
                app.jumpTo("/view/service/notice/signInAddReport.html", "view/service/notice/signInAddReport.html", {
                    ServiceNoticeId: serviceNoticeId,
                    serviceNo: serviceNo,
                    planId: planId
                });

            } else {
                app.toast(data.msg)
            }
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast('操作失败')
            console.log(JSON.stringify(errorMsg))
        });
    }

    // 列表初始化数据
    function initData() {

        app.showWaiting('加载中...')
        var customerName = h("#customerName").val();
        var serviceType = h("#serviceType").html();
        if (serviceType == '请选择服务子类型') {
            serviceType = ""
        }
        var instrumentSerialNumber = h("#instrumentSerialNumber").val();

        ajaxGet(BASE_URL + "cc/notice/getServiceNoticeList", {
            "EnginnerId": app.getUser().enginnerId,
            "state": '5',
            "customerName": customerName,
            "serviceType": serviceType,
            "instrumentSerialNumber": instrumentSerialNumber
        }, function (data) {
            app.closeWaiting()
            if (data.code === 200) {
                var str = '';
                if (data.data && data.data.length > 0) {
                    for (var c = 0; c < data.data.length; c++) {

                        /* var xianshi = '';
                        var enginnerType = data.data[c].enginnerType==undefined?"":data.data[c].enginnerType;
                        var isVip = data.data[c].isVip==undefined?"":data.data[c].isVip;
                        var userIsdpel = data.data[c].userIsdpel==undefined?"":data.data[c].userIsdpel;
                        if(userIsdpel=='1'){
                            xianshi = ''
                        }
                        if(isVip!=''){
                            xianshi += isVip
                        }else{
                            if(enginnerType!=''){
                                xianshi += enginnerType
                            }
                        } */

                        var enginnerType = data.data[c].enginnerType ? data.data[c].enginnerType : "";
                        var planId = data.data[c].planId ? data.data[c].planId : "";
                        var serviceNo = data.data[c].serviceNo ? data.data[c].serviceNo : "";
                        var serviceNoticeId = data.data[c].id ? data.data[c].id : "";
                        var createTime = data.data[c].createTime ? data.data[c].createTime : "";
                        var customerName = data.data[c].customerName ? data.data[c].customerName : "";
                        var serviceType = data.data[c].subServiceType ? data.data[c].subServiceType : "";
                        // str += '<div class="item" onclick="chuli(\''+planId+'\')" >';
                        // str += '<div class="type" id="'+planId+'" serviceNo="'+serviceNo+'" serviceNoticeId="'+serviceNoticeId+'" >';
                        // str += '<p>服务通知编号：<span>'+serviceNo+'</span></p> ';
                        // str += '<p>提交时间：<span>'+createTime+'</span></p>';
                        // str += '<p>客户名称：<span>'+customerName+'</span></p>';
                        // str += '<p>服务子类型：<span>'+serviceType+'</span></p>';
                        // str += '</div></div>';
                        str += '<div class="item" onclick="chuli(\'' + planId  + '\',\'' + customerName + '\')">';
                        str += '<div class="bar" id="' + planId + '" serviceNo="' + serviceNo + '" serviceNoticeId="' + serviceNoticeId + '">';
                        str += '<span class="number">' + data.data[c].serviceNo + '<img src="../../../images/icon_204.png" /></span>';

                        str += '<span class="vip">' + enginnerType + '</span>';

                        str += '</div>';
                        str += '<div class="text autoHeight">';
                        str += '<span class="cen" style="color: #333;">' + customerName + '</span>';
                        str += '</div>';
                        str += '<div class="type">';
                        str += '<p><div class="lpl">提交时间：</div><span>' + createTime + '</span><img src="../../../images/icon_202.png"/></p>';
                        str += '<p><div class="lpl">服务子类型：</div><span>' + serviceType + '</span><img src="../../../images/icon_203.png"/></p>';
                        str += '</div>';
                        str += '</div>';
                    }
                    h('#itemBox').html(str);
                } else {
                    var html = '<div class="nodata">—— 暂无数据 ——</div>';
                    h("#itemBox").html(html);
                }
            } else {
				var html = '<div class="nodata">—— 暂无数据 ——</div>';
				h("#itemBox").html(html);
				app.toast(data.msg);
            }
        }, function (errorMsg) {
           app.closeWaiting();
           var html = '<div class="nodata">—— 暂无数据 ——</div>';
           h("#itemBox").html(html);
           app.toast("数据获取失败，请检查网络连接");
        });
    }

    // 自动计算方法
    function jisuan(date) {
        var estimatedVisitingTime;
        if (date != "1") {
            estimatedVisitingTime = date
        } else {
            estimatedVisitingTime = h("#estimatedVisitingTime").html();
        }
        if (estimatedVisitingTime == null || estimatedVisitingTime == "" || estimatedVisitingTime == "请选择时间") {
            return
        }
        var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
        var estimatedWorkingHours = h("#estimatedWorkingHours").val();
        if (estimatedWorkingHours == null || estimatedWorkingHours == "") {
            return
        }
        var edt = evt + estimatedWorkingHours * 60 * 60 * 1000;
        var estimatedDepartureTime = new Date(edt).Format("yyyy-MM-dd HH:mm");
        h("#estimatedDepartureTime").val(estimatedDepartureTime);
    }

    //判断是否有日志，没有进日志页面，有进报告页面
    function findLog() {
        ajaxGet(BASE_URL + "cc/ServiceLog/getServiceLogList", {
            "enginnerId": app.getUser().enginnerId,
            "planId": planId
        }, function (data) {
            mui("#popover").popover('hide', document.getElementById("div"));
            console.log(JSON.stringify(data))
            if (data.code == 200) {
                mui("#popover").popover('hide', document.getElementById("div"));
				if(data.data && data.data.length > 0){
					//进报告页面
					if (wcState == "yiwancheng") {
						quanbuwancheng();
					} else if (wcState == "weiwancheng") {
						mui("#popover1").popover('toggle', document.getElementById("div1"));
					}
				} else {
					if (wcState == "yiwancheng") {
						quanbuwanchengOnlysave();
						app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html",{
							serviceNoticeId: serviceNoticeId,
							serviceNo: serviceNo,
							planId: planId,
							listName: "autoSignOut"
						});
					} else if (wcState == "weiwancheng") {
						mui("#popover1").popover('toggle', document.getElementById("div1"));
						autoOutLogFlag = true
					}
				}
            } else {
                app.toast(data.msg)
            }
        }, function (errorMsg) {
            app.toast(errorMsg)
        });
    }

    // 全部完成方法
    function quanbuwancheng() {
        app.showWaiting('正在提交...')
        ajaxGet(BASE_URL + "cc/PlanDetails/signOffAutoState", {
            "serviceNoticeId": serviceNoticeId,
            "planId": planId,
            "enginnerId": app.getUser().enginnerId
        }, function (data) {
            app.closeWaiting()
            if (data.code == 200) {
				if(data.data && data.data.length > 0){
					// 判断是否存在离线数据，
					var enginnerId = app.getUser().enginnerId;
					var sqliteTool = new sqliteTools(); 
					sqliteTool.openDatabase();
					for (var i = 0; i < data.data.length; i++) {
						var resData = data.data[i];
						sqliteTool.selectServiceByPlanId(enginnerId, resData.planId, resData, function(flag, offlineData, callBackData) {
							if (offlineData && offlineData.length > 0) {
								sqliteTool.deleteServiceData(offlineData.planId, function(flag) {
									console.log("删除本地数据"+flag)
								})
							}									
						});
					}	
					setTimeout(function() {
						sqliteTool.closeDB();
					}, 200);																
				}
				initData()
                app.toast('操作成功')
            } else {
                app.toast('操作失败')
            }
            mui("#popover").popover('hide', document.getElementById("div"));
            // var assignList = plus.webview.getWebviewById('view/service/notice/autoCheckedOutList.html');
            // assignList.evalJS('initData()')

            // 20200525 修复文档（客户提出20200524测试反馈）93：自动签离的服务页面跳转见“参考-页面跳转6.1”，填写工作日志之后应有相应的页面跳转5.1.2/5.1.3，而不是直接跳转到待接受列表。
            /* var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
            if(indexFSE){
                indexFSE.evalJS('getList("1")')
            }
            var self = plus.webview.currentWebview();
            var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
            if(completedList){
                completedList.evalJS('initData()')
                mui.back()
            }else{
                var completedList1 = plus.webview.create('/view/service/notice/completedList.html','view/service/notice/completedList.html')
                completedList1.show()
                self.close();
            } */
            // 文档要求：5.1.2已填写工作日志，服务通知状态为：已完成（页面含添加报告、还需再次上门按钮）
            app.jumpTo("/view/service/notice/signOutVisitAgain.html", "view/service/notice/signOutVisitAgain.html",
                {
                    ServiceNoticeId: serviceNoticeId,
                    serviceNo: serviceNo,
                    planId: planId,
					complete: 1
                });
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast('操作失败')
            console.log(JSON.stringify(errorMsg))
        });
    }

    // 全部完成方法 （只保存 不跳页）
    function quanbuwanchengOnlysave() {
        app.showWaiting('正在提交...')
        ajaxGet(BASE_URL + "cc/PlanDetails/signOffAutoState", {
            "serviceNoticeId": serviceNoticeId,
            "planId": planId,
            "enginnerId": app.getUser().enginnerId
        }, function (data) {
            app.closeWaiting()
			if(data.data && data.data.length > 0){
				// 判断是否存在离线数据，
				var enginnerId = app.getUser().enginnerId;
				var sqliteTool = new sqliteTools(); 
				sqliteTool.openDatabase();
				for (var i = 0; i < data.data.length; i++) {
					var resData = data.data[i];
					sqliteTool.selectServiceByPlanId(enginnerId, resData.planId, resData, function(flag, offlineData, callBackData) {
						if (offlineData && offlineData.length > 0) {
							sqliteTool.deleteServiceData(offlineData.planId, function(flag) {
								console.log("删除本地数据"+flag)
							})
						}									
					});
				}
				setTimeout(function() {
					sqliteTool.closeDB();
				}, 200);
			}
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast('操作失败')
            console.log(JSON.stringify(errorMsg))
        });
    }
</script>
<!-- js代码 end -->
</body>

</html>
